package com.myself.config;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

/**
 * @author W.S.
 * @version v4.0.0
 * @description
 * @date Created in 2018/8/28 17:32
 */
public class ExpirationMessagePostProcessor implements MessagePostProcessor {

    private final String ttl; // 毫秒
    public ExpirationMessagePostProcessor(String ttl) {
        this.ttl = ttl;
    }
    /**
     * Change (or replace) the message.
     *
     * @param message the message.
     * @return the message.
     * @throws AmqpException an exception.
     */
    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        message.getMessageProperties().setExpiration(ttl);
        return message;
    }
}
